package org.xcorpio.java8.chapter05;

import static java.util.stream.Collectors.toList;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.xcorpio.java8.common.Data;
import org.xcorpio.java8.common.Dish;
import org.xcorpio.java8.common.JacksonUtils;

public class Mapping {

    public static void main(String[] args) {
        List<String> words = Arrays.asList("Java8", "Lambdas", "In", "Action");
        List<Integer> wordLength = words.stream()
             .map(String::length)
             .collect(Collectors.toList());
        System.out.println(wordLength);
        List<Integer> dishNameLength = Data.Menu.stream()
                .map(Dish::getName)
                .map(String::length)
                .collect(toList());
       JacksonUtils.toJson(dishNameLength);
       for (int i = 0; i < 5; ++i) {
           long start = System.currentTimeMillis();
           List<String[]> collect = words.stream()
                   .map(word -> word.split(""))
                   .distinct()
                   .collect(toList());
           System.out.println(JacksonUtils.toJson(collect));
           List<String> uniqueCharacters = words.stream()
                   .map(word -> word.split(""))
                   .flatMap(Arrays::stream)
                   .distinct()
                   .collect(toList());
           System.out.println(uniqueCharacters);
           System.out.println(i + ":" + (System.currentTimeMillis() - start) + "ms");
       }
    }
}
